/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: user
 * Date: 2024-04-05
 * Time: 16:34
 */
import java.util.*;
//牛客->JZ31:栈的压入和弹出
public class Test {
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        // write code here
        Stack<Integer> s = new Stack<>();
        int j = 0;
        for(int i = 0;i < pushV.length;i++){
            s.push(pushV[i]);
            while(j < popV.length&&!s.empty()&&s.peek()==popV[j]){
                s.pop();
                j++;
            }
        }
        return s.empty();
    }
//力扣-》232:用栈实现队列
class MyQueue {
    Stack<Integer> s1;
    Stack<Integer> s2;

    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        if(empty()){
            return 1;
        }
        if(s2.empty()){
            while(!s1.empty()){
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    public int peek() {
        if(empty()){
            return 1;
        }
        if(s2.empty()){
            while(!s1.empty()){
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    public boolean empty() {
        return s1.empty()&&s2.empty();
    }
}
//力扣—》622. 设计循环队列
class MyCircularQueue {
    public int[] elem;
    public int first;
    public int last;
    public MyCircularQueue(int k) {
        elem = new int[k+1];
    }

    public boolean enQueue(int value) {
        if(isFull()){
            return false;
        }
        elem[last] = value;
        last = (last+1)%elem.length;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        first = (first+1)%elem.length;
        return true;
    }

    public int Front() {
        if(isEmpty()){
            return -1;
        }
        return elem[first];
    }

    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        int index = (last == 0)?elem.length - 1:last - 1;
        return elem[index];
    }

    public boolean isEmpty() {

        return first == last;

    }

    public boolean isFull() {
        return ((last + 1 )%elem.length == first);

    }
}



}
